package models;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import play.db.jpa.GenericModel;

@Entity
@Table(name = "survey_answer")
public class SurveyAnswer extends GenericModel {

    @Id
    @Column(name = "survey_answer_id")
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long surveyAnswerId;

    @Column(name = "description")
    public String answerDescription;

    @Column(name = "value")
    public Integer answerValue;

    @ManyToOne(targetEntity = Complaint.class, optional = false)
    @JoinColumn(name = "complaint_id", nullable = false)
    public Complaint complaint;

    @ManyToOne(targetEntity = Survey.class, optional = false)
    @JoinColumn(name = "survey_id", nullable = false)
    public Survey survey;

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = super.hashCode();
	result = prime
		* result
		+ ((answerDescription == null) ? 0 : answerDescription
			.hashCode());
	result = prime * result
		+ ((answerValue == null) ? 0 : answerValue.hashCode());
	result = prime * result
		+ ((complaint == null) ? 0 : complaint.hashCode());
	result = prime * result + ((survey == null) ? 0 : survey.hashCode());
	result = prime * result
		+ ((surveyAnswerId == null) ? 0 : surveyAnswerId.hashCode());
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (!super.equals(obj))
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	SurveyAnswer other = (SurveyAnswer) obj;
	if (answerDescription == null) {
	    if (other.answerDescription != null)
		return false;
	} else if (!answerDescription.equals(other.answerDescription))
	    return false;
	if (answerValue == null) {
	    if (other.answerValue != null)
		return false;
	} else if (!answerValue.equals(other.answerValue))
	    return false;
	if (complaint == null) {
	    if (other.complaint != null)
		return false;
	} else if (!complaint.equals(other.complaint))
	    return false;
	if (survey == null) {
	    if (other.survey != null)
		return false;
	} else if (!survey.equals(other.survey))
	    return false;
	if (surveyAnswerId == null) {
	    if (other.surveyAnswerId != null)
		return false;
	} else if (!surveyAnswerId.equals(other.surveyAnswerId))
	    return false;
	return true;
    }

    @Override
    public String toString() {
	return "SurveyAnswer [surveyAnswerId=" + surveyAnswerId
		+ ", answerDescription=" + answerDescription + ", answerValue="
		+ answerValue + ", complaint=" + complaint + ", survey="
		+ survey + "]";
    }

}
